<%@ page language="java" contentType="text/html" pageEncoding="utf-8"%>
<%@include file="/WEB-INF/pages/common/common.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <%@include file="/WEB-INF/pages/common/head.jsp"%>
    <title><spring:message code="title.function"/></title>
    <script type="text/javascript" language="javascript">
	    var datagrid;
	    var message =$.messager;
	    var href ="";
	    var title ="";
	    var entityDialog;
	    $(function() {
	        datagrid=$('#datagrid').datagrid({
	            url : '${path}/sys/role/ajaxList.do',
	            queryParams: imonJYRH.serializeObject($("#tableForm *"))
	        });
	    });
	    //子页面返回方法
	    function returnResult(){
	        entityDialog.dialog('close');
	        datagrid.datagrid('unselectAll');
	        datagrid.datagrid('reload');
	    }
	    //判断选择单据是否是一条
	    function isChooseOne(rows){
	        var flag = false;
	        if(rows.length >1 ) {
	            message.show({
	                msg : "<spring:message code='msg.choose' arguments='"+rows.length+"'/>",
	                title : '<spring:message code='msg.tip'/>'
	            });
	            flag = false;
	        } else if (rows.length == 0) {
	            message.show({
	                msg : "<spring:message code='msg.please.choose'/>",
	                title : '<spring:message code='msg.tip'/>'
	            });
	            flag = false;
	        }else{
	            flag = true;
	        }
	        return flag;
	    }
	    function append() {
    		//弹出层的相关参数
        	entityDialog = $("#entityDialog").dialog({
    			title : title,collapsible:true,maximizable:true,
    			buttons : [{
    				iconCls:"icon-save",
    				text : '<spring:message code='button.save'/>',
    				handler : function() {
    					$("#entityIFrame")[0].contentWindow.manageForm(message);
    				}
    			},{
    				iconCls:"icon-no",
    				text : '<spring:message code='button.close'/>',
    				handler : function() {
    					//关闭按钮的时候进行关闭按钮
    					entityDialog.dialog('close');
    				}
    			}]
    		});
        	$("#entityIFrame")[0].src=imonJYRH.url(href); 
        	entityDialog.dialog('open');
        	imonJYRH.showZone();
        }
	    function getSelectedIds(){
	        var rows = datagrid.datagrid("getSelections");
	        if (rows.length > 0) {
	            var ids = [];
	            for ( var i = 0; i < rows.length; i++) {
	                ids.push(rows[i].id);
	            }
	            return ids;
	        }else{
	            $.messager.alert('<spring:message code='msg.error'/>','<spring:message code='msg.delete'/>','error');
	            return null;
	        }
	    }
	    function add_() {
	        href ="${path}/sys/role/addUI.do";
	        title ="<spring:message code='msg.create'/>";
	        append();
	    }
	    function modify_(){
	        var rows = datagrid.datagrid("getSelections");
	        if(!isChooseOne(rows)){return;}
	        href = '${path}/sys/role/modifyUI.do?id='+rows[0]['id'];
	        append();
	    }
	    
	    function editRole(){
	    	
	    }
	    
	    function delete_(){
	        var ids = getSelectedIds();
	        $.messager.confirm(
	                '<spring:message code='msg'/>',
	                '<spring:message code='msg.confirm.delete'/>',
	                function(r){
	                    if (r && null!=ids){
	                        imonJYRH.showZone();
	                        $.ajax({
	                            url : imonJYRH.url("${path}/sys/role/ajaxDelete.do"),
	                            cache : false,
	                            data :{'ids':ids.join(',')},
	                            success : function(reMsg) {
	                                if(reMsg.success){
	                                    search_();
	                                    message.show({
	                                        msg : reMsg.msg,
	                                        title : '<spring:message code='msg.tip'/>',
	                                        showType:'slide'
	                                    });
	                                }else{
	                                    message.alert('<spring:message code='msg.tip'/>',reMsg.msg);
	                                }
	                                imonJYRH.hideZone();
	                            }
	                        });
	                    }
	                });
	    }
	    function search_() {
	        datagrid.datagrid('load', imonJYRH.serializeObject($("#tableForm *")));
	    }
	    function reset_(){
	        $("#tableForm *").each(function(){
	            $(":input:not(:checkbox,:radio)",this).val("");
	        });
	    }
    </script>
</head>
<body class="easyui-layout">
<div data-options="region:'north'" style="overflow: hidden;height: 86px;">
    <div class="datagrid-toolbar" style="height: auto">
        <br/>
        <fieldset>
            <legend><spring:message code="label.condition"/></legend>
            <table id="tableForm" class="tableForm" width="100%">
                <tr>
                    <td align="right"><spring:message code="label.role.code"/>：</td>
                    <td>
                        <input type="text" name="code"/>
                    </td>
                    <td align="right"><spring:message code="label.role.name"/>：</td>
                    <td>
                        <input type="text" name="name"/>
                    </td>
                </tr>
            </table>
        </fieldset>
        <br/>
    </div>
</div>
<div data-options="region:'center'">
    <div id="tb">
        <a class="easyui-linkbutton" href="javascript:void(0);" plain="true" iconCls="icon-search" onclick="search_();"><spring:message code="bar.command.search"/></a>
        <a class="easyui-linkbutton" href="javascript:void(0);" plain="true" iconCls="icon-undo" onclick="reset_();"><spring:message code="bar.command.reset"/></a>
        <a class="easyui-linkbutton" href="javascript:void(0);" plain="true" iconCls="icon-add" onclick="add_();"><spring:message code="bar.command.add"/></a>
        <a class="easyui-linkbutton" href="javascript:void(0);" plain="true" iconCls="icon-edit" onclick="modify_();"><spring:message code="bar.command.modify"/></a>
        <a class="easyui-linkbutton" href="javascript:void(0);" plain="true" iconCls="icon-cancel" onclick="delete_();"><spring:message code="bar.command.delete"/></a>
    </div>
    <table id="datagrid" width="100%" toolbar="#tb" striped="true" nowrap="false" fit="true" pagination="true" idField="id" rownumbers="true" fitColumns="true">
        <thead>
        <tr>
        	<th frozenColumns="true" checkbox="true"  field="id"></th>
            <th align='center' width='120' field='code'><spring:message code="table.head.role.code"/></th>
            <th align='center' width='120' field='name'><spring:message code="table.head.role.name"/></th>
            <th align='center' width='120' field='remark'><spring:message code="table.head.role.remark"/></th>
            <th align='center' width='120' field='authorityText'><spring:message code="table.head.role.authority"/></th>
        </tr>
        </thead>
    </table>
</div>
<div id="entityDialog" class="easyui-dialog" style="width:520px;height:380px;"
     data-options="iconCls:'icon-save',resizable:true,modal:true,closed: true,collapsible:true,maximizable:true">
    <iframe scrolling="auto" id='entityIFrame' frameborder="0"  src="" style="width:100%;height:100%;"/>
</div>
</body>
</html>
